<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        function read() {
            var req;
            var v1 = document.getElementsByName("light");  //获取光照长度的text
            var v2 = document.getElementsByName("acceleration");//获取加速度的text
            var xhr = new XMLHttpRequest();//创建对象
            url = "";
            xhr.open("post", url, true);  //配置
            //post:post请求
            //true: 是否为异步发送请求
            xhr.onreadystatechange = function ()  //检测状态是否发生变化
            {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    req = xhr.responseText.split(" ");  //响应正文
                    v1[0].value = req[0];
                    v2[0].value = req[1] + ' ' + req[2] + ' ' + req[3];
                }
            }
            xhr.send("list");  //向网页服务器发送list
            //split : 分割
            //1,2,3,4
            //var z=xhr.responseText.split(" 符号");
            //z[0]  z[1]  z[2] z[3]
        }
        //选择用的哪个单选按钮
        function write_f1(objid) {   
            var xhr = new XMLHttpRequest();//创建对象
            url = "";
            xhr.open("post", url, true);  //配置
            if (objid == 'ledon') {
                xhr.send("\"data1=0data2=1\"");

            } else if (objid == 'ledoff') {
                xhr.send("\"data1=0data2=0\"");

            }
        }
        function write_f2(objid) {
            var xhr = new XMLHttpRequest();//创建对象
            url = "";
            xhr.open("post", url, true);  //配置
            if (objid == 'fmqon') {
                xhr.send("\"data1=1data2=1\"");

            } else if (objid == 'fmqoff') {
                xhr.send("\"data1=1data2=0\"");
            }
        }
    </script>
</head>

<body>
    <!-- checked="checked"  默认选择 -->
    信息采集<br>
    光照强度<input type="text" name="light" value="内容">
    加速度<input type="text" name="acceleration" value="内容">
    <input type="button" name="flash" value="刷新" onclick="read()">
    <br>
    装备控制<br>

    LED灯
    <input type="radio" name="led" id="ledon"  onclick="write_f1(id)">
    on
    <input type="radio" name="led" id="ledoff"  onclick="write_f1(id)">
    off<br>
    蜂鸣器
    <input type="radio" name="fmq" id="fmqon" onclick="write_f2(id)"> 
    on
    <input type="radio" name="fmq" id="fmqoff"  onclick="write_f2(id)">
    off<br>
</body>

</html>